import {getWy,getPlatform} from '@/uni_modules/wy-core/context'
const util={
	_resList(result){  //结果包装
		let {ret,code,msg,data}=result
		code=(code===undefined?(ret>=200?0:1):code);
		result={
			code,
			data,
			msg,
			ret
		}
		return  result
	},
	_resModel(result){  //结果包装
		let {ret,code,msg,data}=result
		code=(code===undefined?(ret>=200?0:1):code); 
		result={
			code,
			data,
			msg,
			ret
		}
		return  result
	},
	_resData(result){  //结果包装
		let {ret,code,msg,data}=result
		code=(code===undefined?(ret>=200?0:1):code); 
		result={
			code,
			data,
			msg,
			ret
		}
		return  data
	},
	_resAction(result){  //结果包装
		let {ret,code,data,msg}=result
		code=(code===undefined?(ret>=200?0:1):code); 
		let {status,tip}=data
		result={
			code:status===1?0:1, //ret>=200?0:1,//
			msg:tip?tip:msg,
			data:data,
			ret
		}
		return result
	},
	getData(ac,option,_params={}){
		let {params,data={},method,header}=option
		header=header?header:{}
		method=method?method:'POST'
		let obj={
			data,
			params:{
				ac,
				...params,
				..._params
			},
			method,
			header,
			res:util._resData,
			option
		} 
		return getWy().request(obj)
	},
	getModel(ac,option,_params={}){
		let {params,data={},method,header}=option
		header=header?header:{}
		method=method?method:'POST'
		let obj={
			data,
			params:{
				ac,
				...params,
				..._params
			},
			method,
			header,
			res:util._resModel,
			option
		}
		return getWy().request(obj)
	},
	getList(ac,option,_params={}){
		let {params,data={},method,header}=option
		header=header?header:{}
		method=method?method:'POST'
		let obj={
			data,
			params:{
				ac,
				...params,
				..._params
			},
			method,
			header,
			res:util._resList,
			option
		}
		return getWy().request(obj)
	},
	doAction(ac,option,_data={},_params={}){
		let {params,data,method,header}=option
		header=header?header:{}
		method=method?method:'POST'
		let obj={
			data:{
				...data,
				..._data
			},
			params:{
				ac,
				...params,
				..._params
			},
			method,
			header,
			res:util._resAction,
			option
		}
		return getWy().request(obj)
	}
}
module.exports= util;
